﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace KD.Sms.ActionCenter
{
    public class Action
    {
        /// <summary>
        /// 本类的唯一实例
        /// </summary>
        private static Action OWNER = null;

        /// <summary>
        /// 获取类的唯一实例
        /// </summary>
        /// <returns></returns>
        public static Action Instance
        {
            get
            {
                if (Action.OWNER == null)
                {
                    Action.OWNER = new Action();
                }
                return Action.OWNER;
            }
        }

        public event EventHandler<CommonEventArgs> CaptureHead;
        public event EventHandler<CommonEventArgs> CaptureCarNo;
        public event EventHandler<CommonEventArgs> CarNumChanged;
        public event EventHandler<CommonEventArgs> SamplingPosMaking;
        public event EventHandler<CommonEventArgs> SamplingAndMakingEnd;
        public event EventHandler<CommonEventArgs> WeightSampleTare;
        public event EventHandler<CommonEventArgs> WeightSampleGross;
        public event EventHandler<CommonEventArgs> RefreshSamplingPail;
        public event EventHandler<CommonEventArgs> ReadCardStm32;
        public event EventHandler<CommonEventArgs> LayingOffComplete;
        public event EventHandler<WaringEventArgs> ShowSystemWaring;
        private List<Entity.SamplingPos> _listPos;
        /// <summary>
        /// 上一次识别车号
        /// </summary>
        private string E_CarNumLast { set; get; }


        /// <summary>
        /// 当前车牌号
        /// </summary>
        public void DoSetCarNum(DiscriminateType type, string carnum, bool error)
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.CarNumChanged, new CommonEventArgs(new Entity.CarDiscriminate(type, carnum, error)));
            if (type == DiscriminateType.LprCapture)
                DoCatchImageCarHead();
        }


        /// <summary>
        /// 事件
        /// </summary>
        public List<Entity.SamplingPos> E_SamplingPos
        {
            set
            {
                _listPos = value;
                //当布点产生变化时刷新展示界面
                EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.SamplingPosMaking, new CommonEventArgs(value));
            }
            get
            {
                return _listPos;
            }
        }

        /// <summary>
        /// 抓拍车头
        /// </summary>
        public void DoCatchImageCarHead()
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.CaptureHead, new CommonEventArgs());
        }

        /// <summary>
        /// 抓拍车牌
        /// </summary>
        public void DoCaptureCarNo()
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.CaptureCarNo, new CommonEventArgs());
        }

        /// <summary>
        /// 刷新样桶数据
        /// </summary>
        public void DoRefreshSamplingPail()
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.RefreshSamplingPail, new CommonEventArgs());
        }

        //触发皮重称重
        public void DoWeightSampleTare()
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.WeightSampleTare, new CommonEventArgs());
        }

        //触发毛重称重
        public void DoWeightSampleGross()
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.WeightSampleGross, new CommonEventArgs());
        }

        /// <summary>
        /// 采样后制样完成
        /// </summary>
        public void DoSamplingAndMakeingEnd()
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.SamplingAndMakingEnd, new CommonEventArgs());
        }

        /// <summary>
        /// 读卡
        /// </summary>
        /// <param name="result"></param>
        public void DoReadCardStm32(Entity.StmResult result)
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.ReadCardStm32, new CommonEventArgs(result));
        }
        /// <summary>
        /// 强制放样完成
        /// </summary>
        /// <param name="result"></param>
        public void DoSendLayingOffComplete()
        {
            EventHelper.DispatchEventAsync<CommonEventArgs>(this, this.LayingOffComplete, new CommonEventArgs());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="str"></param>
        /// <param name="control"></param>
        public void DoSendWaring(string str, bool control)
        {
            EventHelper.DispatchEventAsync<WaringEventArgs>(this, this.ShowSystemWaring, new WaringEventArgs(str, control));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="str"></param>
        /// <param name="control"></param>
        public void DoSendWarings(List<string> str, bool control)
        {
            EventHelper.DispatchEventAsync<WaringEventArgs>(this, this.ShowSystemWaring, new WaringEventArgs(str, control));
        }


    }
}
